#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>

using namespace std;
int main()
{
    pid_t id = fork();
    if (id == 0)
    {
        while (true)
        {
            sleep(2);
            cout << "子进程" << endl;
        }
    }
    else
    {
        while (true)
        {
            sleep(2);
            cout << "父进程" << endl;
        }
        waitpid(id, nullptr, 0);
    }
    return 0;
}